package ar.com.jwa.services;

import java.util.Calendar;
import java.util.Collection;
import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import ar.com.jwa.domain.Game;
import ar.com.jwa.domain.State;
import ar.com.jwa.domain.User;

public class GameServiceTestCase extends ServiceTestCase{
	
	@Autowired
	public GameLocalService gameLocalService; 
	
	@Autowired
	public UserLocalService userLocalService;
	
	@Transactional
	public void testAddGameWithPlayers() {
		
		try {
			
			User user = this.getUserLocalService().getUserByMail("nicolas.hernan.gonzalez@gmail.com");
			
			User user2 = this.getUserLocalService().getUserByMail("chilerojocaliente@hotmail.com");
			
			Calendar cal = Calendar.getInstance();
			
			cal.set(2011,2,2);
			
			Game game = new Game(cal.getTime());
			
			game.confirmPlayer(user);
			
			game.confirmPlayer(user2);
			
			game.setState(State.TO_CONFIRM);
			
			this.gameLocalService.saveGame(game);
		
		} catch (Exception e) {
			e.printStackTrace();
			fail();
		}
		
	}
	
	public void testGetGamesToConfirm(){
		
		try{
			
			Collection<Game> gamesToConfirm = this.getGameLocalService().getAllGamesToConfirm();
			
			for (Game game : gamesToConfirm) {
				assertEquals(true, game.getTheDate().after(new Date()));
				assertEquals(true, game.getState().equals(State.TO_CONFIRM));
			}
		
		}catch (Exception e) {
			e.printStackTrace();
			fail();
		}
	}
	
	public void testGetConfirmedPlayersForGame(){
		
		
		
	}

	
	/**
	 * @return the gameLocalService
	 */
	public GameLocalService getGameLocalService() {
		return gameLocalService;
	}

	/**
	 * @param gameLocalService the gameLocalService to set
	 */
	public void setGameLocalService(GameLocalService gameLocalService) {
		this.gameLocalService = gameLocalService;
	}

	/**
	 * @return the userLocalService
	 */
	public UserLocalService getUserLocalService() {
		return userLocalService;
	}

	/**
	 * @param userLocalService the userLocalService to set
	 */
	public void setUserLocalService(UserLocalService userLocalService) {
		this.userLocalService = userLocalService;
	}
}
